package delayMessage.queue;

import java.util.concurrent.DelayQueue;

/**
 * 任务体的消费者
 *
 * Created by Zhou_Bing on 2018/9/29.
 */
public class MessageConsumer implements Runnable{

    private DelayQueue<Message> queue;

    MessageConsumer(DelayQueue<Message> queue){
        this.queue = queue;
    }

    @Override
    public void run() {
        while(true){
            try {
                Message msg = queue.take();
                System.out.println("消费消息id：" + msg.getId() + " 消息体：" + msg.getBody());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
